package com.zto.mybatis.service.impl;

import com.alibaba.fastjson.JSON;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zto.mybatis.entity.City;
import com.zto.mybatis.mapper.CityMapper;
import com.zto.mybatis.service.CityService;
import com.zto.mybatis.util.JsonUtil;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.session.RowBounds;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
 * @program: sch-diy-parent
 * @description:
 * @author: sch
 * @create: 2020-12-10 14:42
 **/
@Service
@Slf4j
public class CityServiceImpl implements CityService {
    @Autowired
    private CityMapper cityMapper;

    @Override
    public List<City> pageList() {
        Example example = new Example(City.class);
        example.createCriteria().andLike("name", "%北京%")
                .andIn("name", null);
//        int count = cityMapper.selectCountByExample(example);
//        System.out.println("总数量--------" + count);
        PageHelper.startPage(1, 3);
        List<City> cities = cityMapper.selectByExample(example);
        PageInfo pageInfo = new PageInfo(cities);
        System.out.println("总数量--------------" + pageInfo.getTotal());
        System.out.println("分页后数量--------------" + cities.size());

        return cities;
    }
}
